
const Router = require('koa-router');
const home = new Router();
const sqldata = require('./sqldata');

home.get('/', async (ctx)=>{
    // let val=ctx.request.body;
    let arr = []
    let mydata1 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtag="#汪汪星球"`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata1)
    mydata2 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtag="#喵喵星球"`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata2)
    mydata3 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtag="#其他星球"`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata3)
    ctx.body = arr;
})

home.get('/num', async (ctx)=>{
    // let val=ctx.request.body;
    let arr = []
    let mydata1 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-01-01 00:00:00'  and  Wtime<'2021-02-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata1)
    mydata2 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-02-01 00:00:00'  and  Wtime<'2021-03-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata2)
    mydata3 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-03-01 00:00:00'  and  Wtime<'2021-04-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata3)
    mydata4 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-04-01 00:00:00'  and  Wtime<'2021-05-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata4)
    mydata5 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-05-01 00:00:00'  and  Wtime<'2021-06-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata5)
    mydata6 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-06-01 00:00:00'  and  Wtime<'2021-07-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata6)
    mydata7 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-07-01 00:00:00'  and  Wtime<'2021-08-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata7)
    mydata8 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-08-01 00:00:00'  and  Wtime<'2021-09-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata8)
    mydata9 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-09-01 00:00:00'  and  Wtime<'2021-10-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata9)
    mydata10 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-10-01 00:00:00'  and  Wtime<'2021-11-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata10)
    mydata11 = await new Promise((resolve, reject)=>{
        let sql = `select count(*) as count from works where Wtime>='2021-11-01 00:00:00'  and  Wtime<'2021-12-01 00:00:00'`;
        return sqldata(sql, (err, data)=>{
            if(err) reject(err);
            resolve(data);	
        })
    })
    arr.push(mydata11)
    ctx.body = arr;
})

module.exports = home;
 